<?php 
include '../init.php';

if($_POST['password']!=$_POST['passwordcon']){
	echo json_encode(array('code'=>'404','msg'=>'两次输入的密码不一致'));
	exit;
}
$data = array(
	'password'=>md5($_POST['password']),
	);

//如果获取到ID则更新数据，否则新建数据
if(isset($_POST['id'])&&(int)$_POST['id']>0){
	$id = (int)$_POST['id'];
	$r = $mysql->update('user',$data,"id='{$id}'");
	if($r){
		echo json_encode(array('code'=>'000','msg'=>'更新成功'));
	}else{
		echo json_encode(array('code'=>'400','msg'=>'更新失败'));
	}
}else{
	$data['username']=addslashes($_POST['username']);
	$id = $mysql->addRow('user',$data);
	if($id>0){
		echo json_encode(array('code'=>'000','msg'=>'保存成功'));
	}else{
		echo json_encode(array('code'=>'400','msg'=>'保存失败'));
	}
}